<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="论文标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入论文标题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--
    <el-form-item label="文档ID" prop="docId">
      <el-input
        v-model="queryParams.docId"
        placeholder="请输入文档ID"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="论文ID" prop="paperId">
      <el-input
        v-model="queryParams.paperId"
        placeholder="请输入论文ID"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
      <el-form-item label="期刊代码" prop="journalCode">
        <el-input v-model="queryParams.journalCode" placeholder="请输入期刊代码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="关键词" prop="keyword">
        <el-input v-model="queryParams.keyword" placeholder="请输入论文关键词" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
        label-width="68px"></el-form>
      <el-form-item label="论文分类" prop="classification">
        <el-input v-model="queryParams.classification" placeholder="请输入论文分类" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="论文语言" prop="language">
      <el-input
        v-model="queryParams.language"
        placeholder="请输入论文语言"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
      <!-- <el-form-item label="起始页码" prop="startPage">
      <el-input
        v-model="queryParams.startPage"
        placeholder="请输入起始页码"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="结束页码" prop="endPage">
      <el-input
        v-model="queryParams.endPage"
        placeholder="请输入结束页码"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="总页数" prop="totalPageNum">
      <el-input
        v-model="queryParams.totalPageNum"
        placeholder="请输入总页数"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="期刊ISSN号" prop="issn">
      <el-input
        v-model="queryParams.issn"
        placeholder="请输入期刊ISSN号"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="论文CN号" prop="cn">
      <el-input
        v-model="queryParams.cn"
        placeholder="请输入论文CN号"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
      <el-form-item label="期刊名称" prop="hostTitle">
        <el-input v-model="queryParams.hostTitle" placeholder="请输入期刊/书名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="期刊卷号" prop="volume">
      <el-input
        v-model="queryParams.volume"
        placeholder="请输入期刊卷号"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="期刊期号" prop="issue">
      <el-input
        v-model="queryParams.issue"
        placeholder="请输入期刊期号"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="处理单元信息" prop="processingUnit">
      <el-input
        v-model="queryParams.processingUnit"
        placeholder="请输入处理单元信息"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="论文持有号" prop="holdingNumber">
      <el-input
        v-model="queryParams.holdingNumber"
        placeholder="请输入论文持有号"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item>
    <el-form-item label="图书馆代码" prop="libraryCode">
      <el-input
        v-model="queryParams.libraryCode"
        placeholder="请输入图书馆代码"
        clearable
        @keyup.enter.native="handleQuery"
      />
    </el-form-item> -->
      <el-form-item label="所属项目" prop="projectId">
        <el-input v-model="queryParams.projectId" placeholder="请输入所属项目ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['literature:literature:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['literature:literature:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['literature:literature:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['literature:literature:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="literatureList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="论文批次">
              <span>{{ props.row.batch }}</span>
            </el-form-item>
            <el-form-item label="文档ID">
              <span>{{ props.row.docId }}</span>
            </el-form-item>
            <el-form-item label="论文ID">
              <span>{{ props.row.paperId }}</span>
            </el-form-item>
            <el-form-item label="期刊代码">
              <span>{{ props.row.journalCode }}</span>
            </el-form-item>
            <el-form-item label="起始页码">
              <span>{{ props.row.startPage }}</span>
            </el-form-item>
            <el-form-item label="结束页码">
              <span>{{ props.row.endPage }}</span>
            </el-form-item>
            <el-form-item label="总页数">
              <span>{{ props.row.totalPageNum }}</span>
            </el-form-item>
            <el-form-item label="期刊ISSN号">
              <span>{{ props.row.issn }}</span>
            </el-form-item>
            <el-form-item label="论文CN号">
              <span>{{ props.row.cn }}</span>
            </el-form-item>
            <el-form-item label="期刊/书名">
              <span>{{ props.row.hostTitle }}</span>
            </el-form-item>
            <el-form-item label="发表年份">
              <span>{{ props.row.year }}</span>
            </el-form-item>
            <el-form-item label="期刊卷号">
              <span>{{ props.row.volume }}</span>
            </el-form-item>
            <el-form-item label="期刊期号">
              <span>{{ props.row.issue }}</span>
            </el-form-item>
            <el-form-item label="处理单元">
              <span>{{ props.row.processingUnit }}</span>
            </el-form-item>
            <el-form-item label="论文持有号">
              <span>{{ props.row.holdingNumber }}</span>
            </el-form-item>
            <el-form-item label="图书馆代码">
              <span>{{ props.row.libraryCode }}</span>
            </el-form-item>
            <!-- <el-form-item label="所属项目ID">
              <span>{{ props.row.projectId }}</span>
            </el-form-item> -->
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="文献ID" align="center" prop="literatureId" />
      <el-table-column label="论文标题" align="center" prop="title" />
      <el-table-column label="论文关键词" align="center" prop="keyword" />
      <el-table-column label="论文分类" align="center" prop="classification" />
      <el-table-column label="论文语言" align="center" prop="language" />
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['literature:literature:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['literature:literature:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改文献对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="论文批次信息" prop="batch">
          <el-input v-model="form.batch" placeholder="请输入论文批次信息" />
        </el-form-item>
        <el-form-item label="文档ID" prop="docId">
          <el-input v-model="form.docId" placeholder="请输入文档ID" />
        </el-form-item>
        <el-form-item label="论文ID" prop="paperId">
          <el-input v-model="form.paperId" placeholder="请输入论文ID" />
        </el-form-item>
        <el-form-item label="期刊代码" prop="journalCode">
          <el-input v-model="form.journalCode" placeholder="请输入期刊代码" />
        </el-form-item>
        <el-form-item label="论文标题" prop="title">
          <el-input v-model="form.title" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="论文摘要" prop="abstract">
          <el-input v-model="form.abstract" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="论文关键词" prop="keyword">
          <el-input v-model="form.keyword" placeholder="请输入论文关键词" />
        </el-form-item>
        <el-form-item label="论文分类" prop="classification">
          <el-input v-model="form.classification" placeholder="请输入论文分类" />
        </el-form-item>
        <el-form-item label="论文语言" prop="language">
          <el-input v-model="form.language" placeholder="请输入论文语言" />
        </el-form-item>
        <el-form-item label="起始页码" prop="startPage">
          <el-input v-model="form.startPage" placeholder="请输入起始页码" />
        </el-form-item>
        <el-form-item label="结束页码" prop="endPage">
          <el-input v-model="form.endPage" placeholder="请输入结束页码" />
        </el-form-item>
        <el-form-item label="总页数" prop="totalPageNum">
          <el-input v-model="form.totalPageNum" placeholder="请输入总页数" />
        </el-form-item>
        <el-form-item label="期刊ISSN号" prop="issn">
          <el-input v-model="form.issn" placeholder="请输入期刊ISSN号" />
        </el-form-item>
        <el-form-item label="论文CN号" prop="cn">
          <el-input v-model="form.cn" placeholder="请输入论文CN号" />
        </el-form-item>
        <el-form-item label="期刊/书名" prop="hostTitle">
          <el-input v-model="form.hostTitle" placeholder="请输入期刊/书名" />
        </el-form-item>
        <el-form-item label="期刊卷号" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入期刊卷号" />
        </el-form-item>
        <el-form-item label="期刊期号" prop="issue">
          <el-input v-model="form.issue" placeholder="请输入期刊期号" />
        </el-form-item>
        <el-form-item label="处理单元信息" prop="processingUnit">
          <el-input v-model="form.processingUnit" placeholder="请输入处理单元信息" />
        </el-form-item>
        <el-form-item label="论文持有号" prop="holdingNumber">
          <el-input v-model="form.holdingNumber" placeholder="请输入论文持有号" />
        </el-form-item>
        <el-form-item label="图书馆代码" prop="libraryCode">
          <el-input v-model="form.libraryCode" placeholder="请输入图书馆代码" />
        </el-form-item>
        <!-- 因为是多对多的关系，所以新增时还是不指定
         <el-form-item label="所属项目ID" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入所属项目ID" />
        </el-form-item> 
        -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
<script>
import { listLiterature, getLiterature, delLiterature, addLiterature, updateLiterature } from "@/api/literature/literature";

export default {
  name: "Literature",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文献表格数据
      literatureList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        batch: null,
        docId: null,
        paperId: null,
        journalCode: null,
        title: null,
        abstract: null,
        keyword: null,
        classification: null,
        language: null,
        startPage: null,
        endPage: null,
        totalPageNum: null,
        issn: null,
        cn: null,
        hostTitle: null,
        year: null,
        volume: null,
        issue: null,
        processingUnit: null,
        holdingNumber: null,
        libraryCode: null,
        projectId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        title: [
          { required: true, message: "论文标题不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询文献列表 */
    getList() {
      this.loading = true;
      listLiterature(this.queryParams).then(response => {
        this.literatureList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        literatureId: null,
        batch: null,
        docId: null,
        paperId: null,
        journalCode: null,
        title: null,
        abstract: null,
        keyword: null,
        classification: null,
        language: null,
        startPage: null,
        endPage: null,
        totalPageNum: null,
        issn: null,
        cn: null,
        hostTitle: null,
        year: null,
        volume: null,
        issue: null,
        processingUnit: null,
        holdingNumber: null,
        libraryCode: null,
        projectId: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.literatureId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文献";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const literatureId = row.literatureId || this.ids
      getLiterature(literatureId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改文献";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.literatureId != null) {
            updateLiterature(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLiterature(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const literatureIds = row.literatureId || this.ids;
      this.$modal.confirm('是否确认删除文献编号为"' + literatureIds + '"的数据项？').then(function () {
        return delLiterature(literatureIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('literature/literature/export', {
        ...this.queryParams
      }, `literature_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
